#include<iostream>

using namespace std;
#define int long long
const int N = 2e5 + 10;
int a[N];
int n;
signed main()
{
    cin >> n;
    for(int i = 1;i <= n;i ++) cin >> a[i];
    int ret = -1e6 , sum = 0;
    for(int i = 1;i <= n;i ++)
    {
        sum += a[i];
        ret = max(ret , sum);
        if(sum < 0) sum = 0;
    }
    cout << ret << endl;
    return 0;
}